﻿using Microsoft.AspNetCore.Mvc;

namespace MVC高级教程.Controllers
{
    public class RequestController : Controller
    {
        /// <summary>
        /// HttpContext.Requeset
        /// </summary>
        /// <returns></returns>
        public IActionResult Submit()
        {
            var username = Request.Query["username"].ToString(); //对应表单元素的name属性
            var stuID = Request.Query["stuID"];
            var birthday = Convert.ToDateTime(Request.Query["birthday"]);

            //获取所有的请求头
            foreach (var header in Request.Headers)
            { 
                Console.WriteLine(@"请求头名:{0},值:{1}",header.Key,header.Value);
            }

            //键值对的方式获取请求头内容
           // var headvalue = Request.Headers["Referer"];

            //获取所有的Cookies
            foreach (var cookie in Request.Cookies)
            {
                Console.WriteLine(@"cookie名:{0},值:{1}",cookie.Key,cookie.Value);
            }

            //键值对的方式获取某个cookie
            var cookieValue = Request.Cookies["uername"].ToString();
            

            return View();
        }
    }
}
